<template>
  <div>
    <el-card>
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="费用">
          <el-input v-model="form.cost" />
        </el-form-item>
        <el-form-item label="申请时间">
          <el-col :span="11">
            <el-date-picker v-model="form.date" type="date" placeholder="选择日期" style="width: 218%;" />
          </el-col>
        </el-form-item>
        <el-form-item label="用途明细">
          <el-input v-model="form.illustrate" />
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="form.notes" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">提交</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <!--结果，分页-->
    <el-card>
      <template>
        <el-table :data="expenseList" stripe style="width: 100%">
          <el-table-column prop="id" label="序号" width="180" />
          <el-table-column prop="userName" label="申请人姓名" width="180" />
          <el-table-column prop="date1" label="申请时间" width="180" />
          <el-table-column prop="cost" label="报销花费" width="180" />
          <el-table-column prop="illustrate" label="用途明细" width="180" />
          <el-table-column prop="statusFinance" label="财务审批进程" width="180">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.statusFinance == 1" type="info">待审批</el-tag>
              <el-tag v-else-if="scope.row.statusFinance == 2" type="success">已通过</el-tag>
              <el-tag v-else type="danger">驳回</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="statusAdmin" label="管理员审批进程" width="180">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.statusAdmin == 1" type="info">待审批</el-tag>
              <el-tag v-else-if="scope.row.statusAdmin == 2" type="success">已通过</el-tag>
              <el-tag v-else type="danger">驳回</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="notes" label="备注" />
        </el-table>
      </template>
    </el-card>
    <!--分页组件-->
    <el-card>
      <el-pagination
        :current-page="searchModel.page"
        :page-sizes="[5, 10, 20, 50]"
        :page-size="searchModel.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
  </div>
</template>
<script>

import expenseApi from '@/api/expense'
// import { format } from 'date-fns'
// import { parseISO } from 'date-fns/fp'

export default {
  data() {
    return {
      dialogFormVisible: false,
      date: '',
      title: '',
      total: 0,
      searchModel: {
        page: 1,
        pageSize: 10
      },
      expenseList: [],
      form: {
      }
    }
  },
  created() {
    this.getExpenseList()
  },
  methods: {
    onSubmit() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          // this.form.date = this.form.date.toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
          // this.form.date = format(parseISO(this.form.date), 'yyyy-MM-dd')
          expenseApi.addExpense(this.form).then(res => {
            this.$message({
              message: res.msg,
              type: 'success'
            })
          })
          this.getExpenseList()
          this.form = []
        }
      })
      this.form = {}
    },
    getExpenseList() {
      expenseApi.getExpenseListByUser(this.searchModel).then(res => {
        this.expenseList = res.data.rows
        this.total = res.data.total
      })
    }
  }
}
</script>
